﻿#include "OpenGLIndexBuffer.h"

using namespace Kriko;

OpenGLIndexBuffer::OpenGLIndexBuffer(GLuint* data, GLsizei count) : count(count) {
    glGenBuffers(1, &bufferID);
    Bind();
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(GLuint), data, GL_STATIC_DRAW);
    Unbind();
}
OpenGLIndexBuffer::OpenGLIndexBuffer(const std::vector<int>& data) {
    count = data.size();

    glGenBuffers(1, &bufferID);
    Bind();
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(GLuint), &data[0], GL_STATIC_DRAW);
    Unbind();
}

OpenGLIndexBuffer::~OpenGLIndexBuffer() {
    glDeleteBuffers(1, &bufferID);
}

void OpenGLIndexBuffer::Bind() {
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferID);
}

void OpenGLIndexBuffer::Unbind() {
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

GLsizei OpenGLIndexBuffer::GetCount() const {
    return count;
}